package com.sp2p.action.front;

import com.shove.Convert;
import com.shove.util.SqlInfusion;
import com.shove.web.util.DesSecurityUtil;
import com.sp2p.constants.IConstants;
import com.sp2p.entity.User;
import com.sp2p.service.*;
import com.sp2p.service.admin.AdminService;
import com.sp2p.service.admin.RelationService;
import com.sp2p.service.admin.SMSInterfaceService;
import com.sp2p.util.AmountUtil;
import com.sp2p.util.DateUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WchatTrade extends BaseFrontAction {
	public static Log log = LogFactory.getLog(WchatTrade.class);
	private static final long serialVersionUID = 1L;
	
	private static String TOKEN = "gofullwchat";
	private GoFullAwardService goFullAwardService;
	private RechargeService rechargeService;
	private FinanceService financeService;
	private NewsAndMediaReportService newsService;
	protected UserService userService;
	private UserIntegralService userIntegralService;
	private ValidateService validateService;
	private AdminService adminService;
	private RelationService relationService;
	private SMSInterfaceService sMsService;
	
	private MyHomeService myHomeService;

	private HomeInfoSettingService homeInfoSettingService;

	public FinanceService getFinanceService() {
		return financeService;
	}
	public GoFullAwardService getGoFullAwardService() {
		return goFullAwardService;
	}

	public HomeInfoSettingService getHomeInfoSettingService() {
		return homeInfoSettingService;
	}

	public MyHomeService getMyHomeService() {
		return myHomeService;
	}

	public NewsAndMediaReportService getNewsService() {
		return newsService;
	}

	public RechargeService getRechargeService() {
		return rechargeService;
	}
	public ValidateService getValidateService() {
		return validateService;
	}

	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}

	public void setFinanceService(FinanceService financeService) {
		this.financeService = financeService;
	}
	
	public void setGoFullAwardService(GoFullAwardService goFullAwardService) {
		this.goFullAwardService = goFullAwardService;
	}

	public void setHomeInfoSettingService(
			HomeInfoSettingService homeInfoSettingService) {
		this.homeInfoSettingService = homeInfoSettingService;
	}

	public void setMyHomeService(MyHomeService myHomeService) {
		this.myHomeService = myHomeService;
	}

	public void setNewsService(NewsAndMediaReportService newsService) {
		this.newsService = newsService;
	}

	public void setRechargeService(RechargeService rechargeService) {
		this.rechargeService = rechargeService;
	}

	public void setRelationService(RelationService relationService) {
		this.relationService = relationService;
	}

	public void setsMsService(SMSInterfaceService sMsService) {
		this.sMsService = sMsService;
	}

	public void setUserIntegralService(UserIntegralService userIntegralService) {
		this.userIntegralService = userIntegralService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public void setValidateService(ValidateService validateService) {
		this.validateService = validateService;
	}

	
	public String wchatWybList() throws Exception {
		pageBean.setPageNum(request().getParameter("page"));
		pageBean.setPageSize(IConstants.PAGE_SIZE_10);
		
		try {
			financeService.queryLastestBorrowPage(pageBean);
			
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			return "network";
		}
		request().setAttribute("wybList", pageBean.getPage());
		request().setAttribute("currentPage", pageBean.getPageNum());
		request().setAttribute("totalPageNum", pageBean.getTotalPageNum());
		return SUCCESS;
	}
	
	public String wchatWybDetail()  throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
			
			//可用共富券
			int voucherType = 1; //抵用券
			List<Map<String, Object>> availableVoucherList = financeService.queryAvailableVoucherList(user.getId(),voucherType);
			request().setAttribute("availableVoucherList", availableVoucherList);
		}
		
		// 余额宝
		Map<String, String> yebMap = financeService.queryBorrowProduct(1);
		request().setAttribute("yebMap", yebMap);
		Map<String,String> yebAnnualRate =financeService.queryYebAnnualRate();
		request().setAttribute("yebAnnualRate",yebAnnualRate.get("annualRate"));
		// 月利宝
		Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
		request().setAttribute("ylbMap", ylbMap);
		// 季发宝
		Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
		request().setAttribute("jfbMap", jfbMap);
		// 稳赢宝
		Map<String, String> wybMap = financeService.queryWyb();
		request().setAttribute("wybMap", wybMap);
		// 债权
		Map<String, String> debtMap = financeService.queryDebt();
		request().setAttribute("debtMap", debtMap);
		
		String idStr =SqlInfusion.FilteSqlInfusion( request().getParameter("id") == null ? "" : request().getParameter("id"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			// 借款详细
			Map<String, String> borrowDetailMap = financeService.queryBorrowDetail(id,4,0);
			
			if (borrowDetailMap != null && borrowDetailMap.size() > 0) {
				//借款详细
				request().setAttribute("borrowDetailMap", borrowDetailMap);
				//收益详情
				double borrowSum = Convert.strToDouble(borrowDetailMap.get("borrowSum")+"", 0);
				double investAmount = borrowSum;
				double annualRate = Convert.strToDouble(borrowDetailMap.get("annualRate")+"", 0);
				int deadline = Convert.strToInt(borrowDetailMap.get("deadline")+"", 0);
				int paymentMode = Convert.strToInt(borrowDetailMap.get("paymentMode")+"", -1);
				int isDayThe = Convert.strToInt(borrowDetailMap.get("isDayThe")+"", 1);
				
				AmountUtil au = new AmountUtil();
				Map<String,String> earnMap = null;
				String earnAmount = "";
				if(paymentMode == 1){
					//按月等额还款
					earnMap = au.earnCalculateMonth(investAmount, borrowSum, annualRate, deadline, 0, isDayThe, 2,0);
					earnAmount = earnMap.get("msg")+"";
				}else if(paymentMode == 2){
					//先息后本
					earnMap = au.earnCalculateSum(investAmount, borrowSum, annualRate, deadline, 0, isDayThe, 2);
					earnAmount = earnMap.get("msg")+"";
				} else if (paymentMode == 4) {
					// 一次性还款
					earnMap = au.earnCalculateOne(investAmount, borrowSum,annualRate, deadline, 0, isDayThe, 2, 0);
					earnAmount = earnMap.get("msg") + "";
				}
				double monInterest = Convert.strToDouble(earnMap.get("monInterest"),0);
				DecimalFormat   df   =   new   DecimalFormat("#####0.00");
				request().setAttribute("monInterest", df.format(monInterest));
				
				
				// 借款人资料
				Map<String, String> borrowUserMap = financeService.queryUserInfoById(id);
				request().setAttribute("borrowUserMap", borrowUserMap);
				
				//借款记录
				Map<String,String> borrowRecordMap = financeService.queryBorrowRecord(id);
				request().setAttribute("borrowRecordMap", borrowRecordMap);
				
				//担保公司资料
				long agent = Convert.strToLong(borrowDetailMap.get("agent"), -1);
				Map<String,String> agentMap = financeService.getBorrowAgentByAgentId(agent);
				request().setAttribute("agentMap", agentMap);
				
				// 每次点击借款详情时新增浏览量
				financeService.addBrowseCount(id);

			} else {
				return "404";
			}
		} else {
			return "404";
		}
		return "success";
	}
	
	public String loanDescription()  throws Exception {
		String idStr = SqlInfusion.FilteSqlInfusion( request().getParameter("id") == null ? "" : request().getParameter("id"));
		int isForNewUser = Convert.strToInt(request().getParameter("isForNewUser"), 0);
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			// 借款详细
			Map<String, String> borrowDetailMap = financeService.queryBorrowDetail(id,4,isForNewUser);
			
			if (borrowDetailMap != null && borrowDetailMap.size() > 0) {
				//借款详细
				request().setAttribute("borrowDetailMap", borrowDetailMap);
				//收益详情
				double borrowSum = Convert.strToDouble(borrowDetailMap.get("borrowSum")+"", 0);
				double investAmount = borrowSum;
				double annualRate = Convert.strToDouble(borrowDetailMap.get("annualRate")+"", 0);
				int deadline = Convert.strToInt(borrowDetailMap.get("deadline")+"", 0);
				int paymentMode = Convert.strToInt(borrowDetailMap.get("paymentMode")+"", -1);
				int isDayThe = Convert.strToInt(borrowDetailMap.get("isDayThe")+"", 1);
				
				AmountUtil au = new AmountUtil();
				Map<String,String> earnMap = null;
				String earnAmount = "";
				if(paymentMode == 1){
					//按月等额还款
					earnMap = au.earnCalculateMonth(investAmount, borrowSum, annualRate, deadline, 0, isDayThe, 2,0);
					earnAmount = earnMap.get("msg")+"";
				}else if(paymentMode == 2){
					//先息后本
					earnMap = au.earnCalculateSum(investAmount, borrowSum, annualRate, deadline, 0, isDayThe, 2);
					earnAmount = earnMap.get("msg")+"";
				} else if (paymentMode == 4) {
					// 一次性还款
					earnMap = au.earnCalculateOne(investAmount, borrowSum,annualRate, deadline, 0, isDayThe, 2, 0);
					earnAmount = earnMap.get("msg") + "";
				}
				double monInterest = Convert.strToDouble(earnMap.get("monInterest"),0);
				DecimalFormat   df   =   new   DecimalFormat("#####0.00");
				request().setAttribute("monInterest", df.format(monInterest));
				
				
				// 借款人资料
				Map<String, String> borrowUserMap = financeService.queryUserInfoById(id);
				request().setAttribute("borrowUserMap", borrowUserMap);
				
				//借款记录
				Map<String,String> borrowRecordMap = financeService.queryBorrowRecord(id);
				request().setAttribute("borrowRecordMap", borrowRecordMap);
				
				//担保公司资料
				long agent = Convert.strToLong(borrowDetailMap.get("agent"), -1);
				Map<String,String> agentMap = financeService.getBorrowAgentByAgentId(agent);
				request().setAttribute("agentMap", agentMap);
				
				// 每次点击借款详情时新增浏览量
				financeService.addBrowseCount(id);

			} else {
				return "404";
			}
		} else {
			return "404";
		}
		return "success";
	}
	
	public String wchatxsLoanList() throws Exception {
		pageBean.setPageNum(request().getParameter("page"));
		pageBean.setPageSize(IConstants.PAGE_SIZE_10);
		
		try {
			financeService.queryLastestXsBorrowPage(pageBean);
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			return "network";
		}
		request().setAttribute("xsLoans", pageBean.getPage());
		request().setAttribute("currentPage", pageBean.getPageNum());
		request().setAttribute("totalPageNum", pageBean.getTotalPageNum());
		return SUCCESS;
	}
	
	public String wchatXsLoansDetail()  throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserTyjById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
		}
		
		String idStr =SqlInfusion.FilteSqlInfusion( request().getParameter("id") == null ? "" : request().getParameter("id"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			// 借款详细
			Map<String, String> borrowDetailMap = financeService.queryBorrowDetail(id,4,1);
			
			if (borrowDetailMap != null && borrowDetailMap.size() > 0) {
				//借款详细
				request().setAttribute("borrowDetailMap", borrowDetailMap);
				//收益详情
				double borrowSum = Convert.strToDouble(borrowDetailMap.get("borrowSum")+"", 0);
				double investAmount = borrowSum;
				double annualRate = Convert.strToDouble(borrowDetailMap.get("annualRate")+"", 0);
				int deadline = Convert.strToInt(borrowDetailMap.get("deadline")+"", 0);
				int paymentMode = Convert.strToInt(borrowDetailMap.get("paymentMode")+"", -1);
				int isDayThe = Convert.strToInt(borrowDetailMap.get("isDayThe")+"", 1);
				
				AmountUtil au = new AmountUtil();
				Map<String,String> earnMap = null;
				String earnAmount = "";
				if(paymentMode == 1){
					//按月等额还款
					earnMap = au.earnCalculateMonth(investAmount, borrowSum, annualRate, deadline, 0, isDayThe, 2,0);
					earnAmount = earnMap.get("msg")+"";
				}else if(paymentMode == 2){
					//先息后本
					earnMap = au.earnCalculateSum(investAmount, borrowSum, annualRate, deadline, 0, isDayThe, 2);
					earnAmount = earnMap.get("msg")+"";
				} else if (paymentMode == 4) {
					// 一次性还款
					earnMap = au.earnCalculateOne(investAmount, borrowSum,annualRate, deadline, 0, isDayThe, 2, 0);
					earnAmount = earnMap.get("msg") + "";
				}
				double monInterest = Convert.strToDouble(earnMap.get("monInterest"),0);
				DecimalFormat   df   =   new   DecimalFormat("#####0.00");
				request().setAttribute("monInterest", df.format(monInterest));
				
				
				// 借款人资料
				Map<String, String> borrowUserMap = financeService.queryUserInfoById(id);
				request().setAttribute("borrowUserMap", borrowUserMap);
				
				//借款记录
				Map<String,String> borrowRecordMap = financeService.queryBorrowRecord(id);
				request().setAttribute("borrowRecordMap", borrowRecordMap);
				
				//担保公司资料
				long agent = Convert.strToLong(borrowDetailMap.get("agent"), -1);
				Map<String,String> agentMap = financeService.getBorrowAgentByAgentId(agent);
				request().setAttribute("agentMap", agentMap);
				
				// 每次点击借款详情时新增浏览量
				financeService.addBrowseCount(id);

			} else {
				return "404";
			}
		} else {
			return "404";
		}
		return "success";
	}
	
	public String loanWybDetailInvest() throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
			
			//可用共富券
			int voucherType = 1; //抵用券
			List<Map<String, Object>> availableVoucherList = financeService.queryAvailableVoucherList(user.getId(),voucherType);
			request().setAttribute("availableVoucherList", availableVoucherList);
		}
		
		List<Map<String, Object>> wyblist = financeService.queryBorrowList();  //稳赢宝list
		
		if (wyblist.size()>0) {
			
			// 余额宝
			Map<String, String> yebMap = financeService.queryBorrowProduct(1);
			request().setAttribute("yebMap", yebMap);
			Map<String,String> yebAnnualRate =financeService.queryYebAnnualRate();
			request().setAttribute("yebAnnualRate",yebAnnualRate.get("annualRate"));
			// 月利宝
			Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
			request().setAttribute("ylbMap", ylbMap);
			// 季发宝
			Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
			request().setAttribute("jfbMap", jfbMap);
			// 稳赢宝
			Map<String, String> wybMap = financeService.queryWyb();
			request().setAttribute("wybMap", wybMap);
			// 债权
			Map<String, String> debtMap = financeService.queryDebt();
			request().setAttribute("debtMap", debtMap);
			//借款详情
			request().setAttribute("wyblist", wyblist);
		} else {
			return "404";
		}
		return SUCCESS;
	}
	
	public String wchatYebDetail()  throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
			
			//可用共富券
			int voucherType = 1; //抵用券
			List<Map<String, Object>> availableVoucherList = financeService.queryAvailableVoucherList(user.getId(),voucherType);
			request().setAttribute("availableVoucherList", availableVoucherList);
		}
		
		// 余额宝
		Map<String, String> yebMap = financeService.queryBorrowProduct(1);
		request().setAttribute("yebMap", yebMap);
		// 月利宝
		Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
		request().setAttribute("ylbMap", ylbMap);
		// 季发宝
		Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
		request().setAttribute("jfbMap", jfbMap);
		// 稳赢宝
		Map<String, String> wybMap = financeService.queryWyb();
		request().setAttribute("wybMap", wybMap);
		// 债权
		Map<String, String> debtMap = financeService.queryDebt();
		request().setAttribute("debtMap", debtMap);
		
		String idStr =SqlInfusion.FilteSqlInfusion(request().getParameter("pid") == null ? "" : request()
				.getParameter("pid"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			Map<String, String> productDetailMap = financeService.queryProductDetailById(id,1);
			Map<String,String> yebAnnualRate = financeService.queryYebAnnualRate();
			productDetailMap.put("yebAnnualRate", yebAnnualRate.get("annualRate"));
			request().setAttribute("productDetailMap", productDetailMap);
		}
		
		return SUCCESS;
	}
	
	public String queryYebInvestBypId()  throws Exception {
		String idStr =SqlInfusion.FilteSqlInfusion( request().getParameter("pid") == null ? "" : request().getParameter("pid"));
		Long id = Convert.strToLong(idStr, -1);
		String curPage =SqlInfusion.FilteSqlInfusion( request().getParameter("page") == null ? "" : request().getParameter("page"));
		
		pageBean.setPageNum(curPage);
		pageBean.setPageSize(IConstants.PAGE_SIZE_10);
		// 投资记录		
		financeService.queryYebInvestBypId(id,pageBean);
		request().setAttribute("yebInvestRecordList", pageBean.getPage());
		request().setAttribute("currentPage", pageBean.getPageNum());
		request().setAttribute("totalPageNum", pageBean.getTotalPageNum());
		request().setAttribute("pid", idStr);
		return SUCCESS;
	}
	
	public String queryYlbInvestBypId()  throws Exception {
		String idStr =SqlInfusion.FilteSqlInfusion( request().getParameter("pid") == null ? "" : request().getParameter("pid"));
		Long id = Convert.strToLong(idStr, -1);
		String curPage =SqlInfusion.FilteSqlInfusion( request().getParameter("page") == null ? "" : request().getParameter("page"));
		
		pageBean.setPageNum(curPage);
		pageBean.setPageSize(IConstants.PAGE_SIZE_10);
		// 投资记录		
		financeService.queryInvestBypId(id,pageBean);
		request().setAttribute("ylbInvestRecordList", pageBean.getPage());
		request().setAttribute("currentPage", pageBean.getPageNum());
		request().setAttribute("totalPageNum", pageBean.getTotalPageNum());
		request().setAttribute("pid", idStr);
		return SUCCESS;
	}
	
	public String queryJfbInvestBypId()  throws Exception {
		String idStr =SqlInfusion.FilteSqlInfusion( request().getParameter("pid") == null ? "" : request().getParameter("pid"));
		Long id = Convert.strToLong(idStr, -1);
		String curPage =SqlInfusion.FilteSqlInfusion( request().getParameter("page") == null ? "" : request().getParameter("page"));
		
		pageBean.setPageNum(curPage);
		pageBean.setPageSize(IConstants.PAGE_SIZE_10);
		// 投资记录		
		financeService.queryInvestBypId(id,pageBean);
		request().setAttribute("jfbInvestRecordList", pageBean.getPage());
		request().setAttribute("currentPage", pageBean.getPageNum());
		request().setAttribute("totalPageNum", pageBean.getTotalPageNum());
		request().setAttribute("pid", idStr);
		return SUCCESS;
	}
	
	public String queryWybInvestBypId()  throws Exception {
		String idStr =SqlInfusion.FilteSqlInfusion( request().getParameter("id") == null ? "" : request().getParameter("id"));
		Long id = Convert.strToLong(idStr, -1);
		String curPage =SqlInfusion.FilteSqlInfusion( request().getParameter("page") == null ? "" : request().getParameter("page"));
		
		pageBean.setPageNum(curPage);
		pageBean.setPageSize(IConstants.PAGE_SIZE_10);
		// 投资记录		
		financeService.queryInvestBybId(id,pageBean);
		request().setAttribute("wybInvestRecordList", pageBean.getPage());
		request().setAttribute("currentPage", pageBean.getPageNum());
		request().setAttribute("totalPageNum", pageBean.getTotalPageNum());
		request().setAttribute("id", idStr);
		return SUCCESS;
	}
	
	public String queryXsInvestById()  throws Exception {
		String idStr =SqlInfusion.FilteSqlInfusion( request().getParameter("id") == null ? "" : request().getParameter("id"));
		Long id = Convert.strToLong(idStr, -1);
		String curPage =SqlInfusion.FilteSqlInfusion( request().getParameter("page") == null ? "" : request().getParameter("page"));
		
		pageBean.setPageNum(curPage);
		pageBean.setPageSize(IConstants.PAGE_SIZE_10);
		// 投资记录		
		financeService.queryInvestBybId(id,pageBean);
		request().setAttribute("xsInvestRecordList", pageBean.getPage());
		request().setAttribute("currentPage", pageBean.getPageNum());
		request().setAttribute("totalPageNum", pageBean.getTotalPageNum());
		request().setAttribute("id", idStr);
		return SUCCESS;
	}
	
	public String loanXsDetailInvest() throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserTyjById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
		}
		
		String idStr =SqlInfusion.FilteSqlInfusion(request().getParameter("id") == null ? "" : request()
				.getParameter("id"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			// 借款详细
			Map<String, String> borrowDetailMap = financeService.queryBorrowDetail(id,4,1);
			
			if (borrowDetailMap != null && borrowDetailMap.size() > 0) {
				//借款详细
				request().setAttribute("borrowDetailMap", borrowDetailMap);
				//收益详情
				double borrowSum = Convert.strToDouble(borrowDetailMap.get("borrowSum")+"", 0);
				double investAmount = borrowSum;
				double annualRate = Convert.strToDouble(borrowDetailMap.get("annualRate")+"", 0);
				int deadline = Convert.strToInt(borrowDetailMap.get("deadline")+"", 0);
				int paymentMode = Convert.strToInt(borrowDetailMap.get("paymentMode")+"", -1);
				int isDayThe = Convert.strToInt(borrowDetailMap.get("isDayThe")+"", 1);
				
				AmountUtil au = new AmountUtil();
				Map<String,String> earnMap = null;
				String earnAmount = "";
				if(paymentMode == 1){
					//按月等额还款
					earnMap = au.earnCalculateMonth(investAmount, borrowSum, annualRate, deadline, 0, isDayThe, 2,0);
					earnAmount = earnMap.get("msg")+"";
				}else if(paymentMode == 2){
					//先息后本
					earnMap = au.earnCalculateSum(investAmount, borrowSum, annualRate, deadline, 0, isDayThe, 2);
					earnAmount = earnMap.get("msg")+"";
				} else if (paymentMode == 4) {
					// 一次性还款
					earnMap = au.earnCalculateOne(investAmount, borrowSum,annualRate, deadline, 0, isDayThe, 2, 0);
					earnAmount = earnMap.get("msg") + "";
				}
				double monInterest = Convert.strToDouble(earnMap.get("monInterest"),0);
				DecimalFormat   df   =   new   DecimalFormat("#####0.00");
				request().setAttribute("monInterest", df.format(monInterest));
				
				
				// 借款人资料
				Map<String, String> borrowUserMap = financeService.queryUserInfoById(id);
				request().setAttribute("borrowUserMap", borrowUserMap);
				
				//借款记录
				Map<String,String> borrowRecordMap = financeService.queryBorrowRecord(id);
				request().setAttribute("borrowRecordMap", borrowRecordMap);
				
				//担保公司资料
				long agent = Convert.strToLong(borrowDetailMap.get("agent"), -1);
				Map<String,String> agentMap = financeService.getBorrowAgentByAgentId(agent);
				request().setAttribute("agentMap", agentMap);
				
				// 每次点击借款详情时新增浏览量
				financeService.addBrowseCount(id);

			} else {
				return "404";
			}
		} else {
			return "404";
		}
		return SUCCESS;
	}
	
	public String loanYebDetailInvest() throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
			
			//可用共富券
			int voucherType = 1; //抵用券
			List<Map<String, Object>> availableVoucherList = financeService.queryAvailableVoucherList(user.getId(),voucherType);
			request().setAttribute("availableVoucherList", availableVoucherList);
			List<Map<String, Object>> list = financeService.queryYebInvestAmount(user.getId());
			String i = "0";
			if(list.get(0).get("money")!=null){
				i = list.get(0).get("money").toString();
			}
			Double s =  Double.parseDouble(i);
			request().setAttribute("moneys",100000-s );
		}
		// 余额宝
		Map<String, String> yebMap = financeService.queryBorrowProduct(1);
		request().setAttribute("yebMap", yebMap);
		// 月利宝
		Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
		request().setAttribute("ylbMap", ylbMap);
		// 季发宝
		Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
		request().setAttribute("jfbMap", jfbMap);
		// 稳赢宝
		Map<String, String> wybMap = financeService.queryWyb();
		request().setAttribute("wybMap", wybMap);
		// 债权
		Map<String, String> debtMap = financeService.queryDebt();
		request().setAttribute("debtMap", debtMap);
		
		String idStr =SqlInfusion.FilteSqlInfusion(request().getParameter("pid") == null ? "" : request()
				.getParameter("pid"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			Map<String, String> productDetailMap = financeService.queryProductDetailById(id,1);
			Map<String,String> yebAnnualRate = financeService.queryYebAnnualRate();
			productDetailMap.put("yebAnnualRate", yebAnnualRate.get("annualRate"));
			request().setAttribute("productDetailMap", productDetailMap);
		}
		return SUCCESS;
	}
	
	public String wchatYlbDetail()  throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
			
			//可用共富券
			int voucherType = 1; //抵用券
			List<Map<String, Object>> availableVoucherList = financeService.queryAvailableVoucherList(user.getId(),voucherType);
			request().setAttribute("availableVoucherList", availableVoucherList);
		}
		
		// 余额宝
		Map<String, String> yebMap = financeService.queryBorrowProduct(1);
		request().setAttribute("yebMap", yebMap);
		Map<String,String> yebAnnualRate =financeService.queryYebAnnualRate();
		request().setAttribute("yebAnnualRate",yebAnnualRate.get("annualRate"));
		// 月利宝
		Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
		request().setAttribute("ylbMap", ylbMap);
		// 季发宝
		Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
		request().setAttribute("jfbMap", jfbMap);
		// 稳赢宝
		Map<String, String> wybMap = financeService.queryWyb();
		request().setAttribute("wybMap", wybMap);
		// 债权
		Map<String, String> debtMap = financeService.queryDebt();
		request().setAttribute("debtMap", debtMap);
		
		String idStr =SqlInfusion.FilteSqlInfusion(request().getParameter("pid") == null ? "" : request()
				.getParameter("pid"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			Map<String, String> productDetailMap = financeService.queryProductDetailById(id,2);
			request().setAttribute("productDetailMap", productDetailMap);
		}
		
		
		return SUCCESS;
	}
	
	public String loanYlbDetailInvest() throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
			
			//可用共富券
			int voucherType = 1; //抵用券
			List<Map<String, Object>> availableVoucherList = financeService.queryAvailableVoucherList(user.getId(),voucherType);
			request().setAttribute("availableVoucherList", availableVoucherList);
		}
		
		// 余额宝
		Map<String, String> yebMap = financeService.queryBorrowProduct(1);
		request().setAttribute("yebMap", yebMap);
		Map<String,String> yebAnnualRate =financeService.queryYebAnnualRate();
		request().setAttribute("yebAnnualRate",yebAnnualRate.get("annualRate"));
		// 月利宝
		Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
		request().setAttribute("ylbMap", ylbMap);
		// 季发宝
		Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
		request().setAttribute("jfbMap", jfbMap);
		// 稳赢宝
		Map<String, String> wybMap = financeService.queryWyb();
		request().setAttribute("wybMap", wybMap);
		// 债权
		Map<String, String> debtMap = financeService.queryDebt();
		request().setAttribute("debtMap", debtMap);
		
		
		String idStr =SqlInfusion.FilteSqlInfusion(request().getParameter("pid") == null ? "" : request()
				.getParameter("pid"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			Map<String, String> productDetailMap = financeService.queryProductDetailById(id,2);
			request().setAttribute("productDetailMap", productDetailMap);
		}
		return SUCCESS;
	}
	
	
	public String wchatJfbDetail()  throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
			
			//可用共富券
			int voucherType = 1; //抵用券
			List<Map<String, Object>> availableVoucherList = financeService.queryAvailableVoucherList(user.getId(),voucherType);
			request().setAttribute("availableVoucherList", availableVoucherList);
		}
		
		// 余额宝
		Map<String, String> yebMap = financeService.queryBorrowProduct(1);
		request().setAttribute("yebMap", yebMap);
		Map<String,String> yebAnnualRate =financeService.queryYebAnnualRate();
		request().setAttribute("yebAnnualRate",yebAnnualRate.get("annualRate"));
		// 月利宝
		Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
		request().setAttribute("ylbMap", ylbMap);
		// 季发宝
		Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
		request().setAttribute("jfbMap", jfbMap);
		// 稳赢宝
		Map<String, String> wybMap = financeService.queryWyb();
		request().setAttribute("wybMap", wybMap);
		// 债权
		Map<String, String> debtMap = financeService.queryDebt();
		request().setAttribute("debtMap", debtMap);
		
		String idStr =SqlInfusion.FilteSqlInfusion(request().getParameter("pid") == null ? "" : request()
				.getParameter("pid"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			Map<String, String> productDetailMap = financeService.queryProductDetailById(id,3);
			request().setAttribute("productDetailMap", productDetailMap);
		}
		
		return SUCCESS;
	}
	
	public String loanJfbDetailInvest() throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
			
			// 余额宝
			Map<String, String> yebMap = financeService.queryBorrowProduct(1);
			request().setAttribute("yebMap", yebMap);
			Map<String,String> yebAnnualRate =financeService.queryYebAnnualRate();
			request().setAttribute("yebAnnualRate",yebAnnualRate.get("annualRate"));
			// 月利宝
			Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
			request().setAttribute("ylbMap", ylbMap);
			// 季发宝
			Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
			request().setAttribute("jfbMap", jfbMap);
			// 稳赢宝
			Map<String, String> wybMap = financeService.queryWyb();
			request().setAttribute("wybMap", wybMap);
			// 债权
			Map<String, String> debtMap = financeService.queryDebt();
			request().setAttribute("debtMap", debtMap);
			
			//可用共富券
			int voucherType = 1; //抵用券
			List<Map<String, Object>> availableVoucherList = financeService.queryAvailableVoucherList(user.getId(),voucherType);
			request().setAttribute("availableVoucherList", availableVoucherList);
		}
		
		String idStr =SqlInfusion.FilteSqlInfusion(request().getParameter("pid") == null ? "" : request()
				.getParameter("pid"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			Map<String, String> productDetailMap = financeService.queryProductDetailById(id,3);
			request().setAttribute("productDetailMap", productDetailMap);
		}
		return SUCCESS;
	}
	
	public String wchatProductDescription()  throws Exception {
		String idStr =SqlInfusion.FilteSqlInfusion(request().getParameter("pid") == null ? "" : request().getParameter("pid"));
		String pType =SqlInfusion.FilteSqlInfusion(request().getParameter("productType") == null ? "" : request().getParameter("productType"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			int productType = Convert.strToInt(pType, -1);
			Map<String, String> productDetailMap = financeService.queryProductDetailById(id,productType);
			Map<String,String> yebAnnualRate = financeService.queryYebAnnualRate();
			productDetailMap.put("yebAnnualRate", yebAnnualRate.get("annualRate"));
			
			String publishTime = productDetailMap.get("publishTime");
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String remainTimeEnd = df.format(DateUtil.dateAddDay(DateUtil.strToDate(publishTime), 3));
			String repayTimeEnd = df.format(DateUtil.dateAddMonth(DateUtil.strToDate(publishTime), 3));//到期日
			productDetailMap.put("remainTimeEnd", remainTimeEnd);
			productDetailMap.put("repayTimeEnd", repayTimeEnd);
			request().setAttribute("productDetailMap", productDetailMap);
		}
		
		return SUCCESS;
	}
	
	public String wchatDebtList() throws Exception {
		pageBean.setPageNum(request().getParameter("page"));
		pageBean.setPageSize(IConstants.PAGE_SIZE_10);
		
		try {
			financeService.queryLastestDebtPage(pageBean);
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			return "network";
		}
		request().setAttribute("debtList", pageBean.getPage());
		request().setAttribute("currentPage", pageBean.getPageNum());
		request().setAttribute("totalPageNum", pageBean.getTotalPageNum());
		return SUCCESS;
	}
	
	public String wchatDebtDetail()  throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
			
			// 余额宝
			Map<String, String> yebMap = financeService.queryBorrowProduct(1);
			request().setAttribute("yebMap", yebMap);
			Map<String,String> yebAnnualRate =financeService.queryYebAnnualRate();
			request().setAttribute("yebAnnualRate",yebAnnualRate.get("annualRate"));
			// 月利宝
			Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
			request().setAttribute("ylbMap", ylbMap);
			// 季发宝
			Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
			request().setAttribute("jfbMap", jfbMap);
			// 稳赢宝
			Map<String, String> wybMap = financeService.queryWyb();
			request().setAttribute("wybMap", wybMap);
			// 债权
			Map<String, String> debtMap = financeService.queryDebt();
			request().setAttribute("debtMap", debtMap);
			//可用共富券
			int voucherType = 1; //抵用券
			List<Map<String, Object>> availableVoucherList = financeService.queryAvailableVoucherList(user.getId(),voucherType);
			request().setAttribute("availableVoucherList", availableVoucherList);
		}
		
		String idStr =SqlInfusion.FilteSqlInfusion( request().getParameter("id") == null ? "" : request().getParameter("id"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			//债权详情
			long debtId = Convert.strToLong(idStr, -1);
			Map<String, String> debtDetailMap = financeService.queryDebtDetailById(debtId);
			
			if (debtDetailMap != null && debtDetailMap.size() > 0) {
				request().setAttribute("debtDetailMap", debtDetailMap);
				
				long borrowId = Convert.strToLong(debtDetailMap.get("parentBId"), -1);
				// 借款人资料
				Map<String, String> borrowUserMap = financeService.queryUserInfoById(borrowId);
				request().setAttribute("borrowUserMap", borrowUserMap);
				
				//借款记录
				Map<String,String> borrowRecordMap = financeService.queryBorrowRecord(borrowId);
				request().setAttribute("borrowRecordMap", borrowRecordMap);
				
				//担保公司资料
				long agent = Convert.strToLong(debtDetailMap.get("agent"), -1);
				Map<String,String> agentMap = financeService.getBorrowAgentByAgentId(agent);
				request().setAttribute("agentMap", agentMap);
			}
		}
		
		return SUCCESS;
	}
	
	public String loanDebtDescription()  throws Exception {
		String idStr =SqlInfusion.FilteSqlInfusion( request().getParameter("id") == null ? "" : request().getParameter("id"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			//债权详情
			long debtId = Convert.strToLong(idStr, -1);
			Map<String, String> debtDetailMap = financeService.queryDebtDetailById(debtId);
			
			if (debtDetailMap != null && debtDetailMap.size() > 0) {
				request().setAttribute("debtDetailMap", debtDetailMap);
				
				long borrowId = Convert.strToLong(debtDetailMap.get("parentBId"), -1);
				// 借款人资料
				Map<String, String> borrowUserMap = financeService.queryUserInfoById(borrowId);
				request().setAttribute("borrowUserMap", borrowUserMap);
				
				//借款记录
				Map<String,String> borrowRecordMap = financeService.queryBorrowRecord(borrowId);
				request().setAttribute("borrowRecordMap", borrowRecordMap);
				
				//担保公司资料
				long agent = Convert.strToLong(debtDetailMap.get("agent"), -1);
				Map<String,String> agentMap = financeService.getBorrowAgentByAgentId(agent);
				request().setAttribute("agentMap", agentMap);
			}
		}
		
		return SUCCESS;
	}
	
	public String queryDebtInvestBypId()  throws Exception {
		String idStr =SqlInfusion.FilteSqlInfusion( request().getParameter("id") == null ? "" : request().getParameter("id"));
		String pidStr =SqlInfusion.FilteSqlInfusion( request().getParameter("pid") == null ? "" : request().getParameter("pid"));
		Long id = Convert.strToLong(pidStr, -1);
		String curPage =SqlInfusion.FilteSqlInfusion( request().getParameter("page") == null ? "" : request().getParameter("page"));
		
		pageBean.setPageNum(curPage);
		pageBean.setPageSize(IConstants.PAGE_SIZE_10);
		// 投资记录		
		financeService.queryInvestBybId(id,pageBean);
		List<Map<String,Object>> list = pageBean.getPage();
		if(null != list && list.size() > 0 ){
			request().setAttribute("borrowProduct", list.get(0).get("borrowProduct"));;
		}
		request().setAttribute("debtInvestRecordList", pageBean.getPage());
		request().setAttribute("currentPage", pageBean.getPageNum());
		request().setAttribute("totalPageNum", pageBean.getTotalPageNum());
		request().setAttribute("id", idStr);
		return SUCCESS;
	}
	public String loanDebtDetailInvest()  throws Exception {
		User user = (User) session().getAttribute("user");
		if(user != null){
			Map<String, String> accmountStatisMap = userService.queryUserById(user.getId());
			request().setAttribute("accmountStatisMap", accmountStatisMap);
			
			//可用共富券
			int voucherType = 1; //抵用券
			List<Map<String, Object>> availableVoucherList = financeService.queryAvailableVoucherList(user.getId(),voucherType);
			request().setAttribute("availableVoucherList", availableVoucherList);
		}
		
		List<Map<String, Object>> debtList = financeService.queryDebtList(user.getId());  //稳赢宝list
		
		if (debtList.size()>0) {
			
			// 余额宝
			Map<String, String> yebMap = financeService.queryBorrowProduct(1);
			request().setAttribute("yebMap", yebMap);
			Map<String,String> yebAnnualRate =financeService.queryYebAnnualRate();
			request().setAttribute("yebAnnualRate",yebAnnualRate.get("annualRate"));
			// 月利宝
			Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
			request().setAttribute("ylbMap", ylbMap);
			// 季发宝
			Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
			request().setAttribute("jfbMap", jfbMap);
			// 稳赢宝
			Map<String, String> wybMap = financeService.queryWyb();
			request().setAttribute("wybMap", wybMap);
			// 债权
			Map<String, String> debtMap = financeService.queryDebt();
			request().setAttribute("debtMap", debtMap);
			//借款详情
			request().setAttribute("debtlist", debtList);
		} else {
			return "404";
		}
		
		return SUCCESS;
	}

	/**
	 * 连连快捷支付
	 * */
	public String quickpayment()  throws Exception {
		// 获取用户的信息
		User user = (User) session().getAttribute(IConstants.SESSION_USER);
		
		//判断用户是否已经实名认证
		Map<String, String> materialsauthMap = userService.isCheckIDCard(user.getId());
		if(materialsauthMap == null || materialsauthMap.size() == 0 || !(materialsauthMap.get("auditStatus").equals("3"))){
			request().setAttribute("userMaterialsauthStats", 0);
		}else{
			request().setAttribute("userMaterialsauthStats", materialsauthMap.get("auditStatus"));
		}
		return SUCCESS;
	}

	/**
	 * 通联协议支付
	 * */
	public String allinPayQuickpayment()  throws Exception {
		// 获取用户的信息
		User user = (User) session().getAttribute(IConstants.SESSION_USER);

		//判断用户是否已经实名认证
		Map<String, String> materialsauthMap = userService.isCheckIDCard(user.getId());
		if(materialsauthMap == null || materialsauthMap.size() == 0 || !(materialsauthMap.get("auditStatus").equals("3"))){
			request().setAttribute("userMaterialsauthStats", 0);
		}else{
			request().setAttribute("userMaterialsauthStats", materialsauthMap.get("auditStatus"));
		}
		return SUCCESS;
	}
	/**
	 * 提现信息加载
	 * 
	 * @return
	 * @throws Exception
	 */
	public String withdrawLoad() throws Exception {
		// 获取用户的信息
		User user = (User) session().getAttribute(IConstants.SESSION_USER);
		Long userId = user.getId();// 获得用户编号
		
		Map<String, String>  withdrawNumMap = rechargeService.querywithdrawNum(userId);//已提现次数
		request().setAttribute("withdrawNum", withdrawNumMap.get("withdrawNum"));
		
		Map<String, String>  freeNumMap = rechargeService.queryNum();//提现免费次数
		request().setAttribute("freeNum", freeNumMap.get("freeNum"));
		
		Map<String, String>  FeeRateMap = rechargeService.queryFeeRate();//提现费率
		request().setAttribute("FeeRate", FeeRateMap.get("FeeRate"));
		//可用余额
		String[] vals = moneyVal(userId);
		request().setAttribute("usableSum", vals[1]);
		
		List<Map<String, Object>> banks = homeInfoSettingService.querySuccessBankInfoList(userId);
		request().setAttribute("banks", banks);
		return SUCCESS;
	}
	
	public String withdraw_step2() throws Exception {
		// 获取用户的信息
		User user = (User) session().getAttribute(IConstants.SESSION_USER);
		Long userId = user.getId();// 获得用户编号
		
		Map<String, String>  withdrawNumMap = rechargeService.querywithdrawNum(userId);//提现次数
		request().setAttribute("withdrawNum", withdrawNumMap.get("withdrawNum"));
		
		Map<String, String>  freeNumMap = rechargeService.queryNum();//提现免费次数
		request().setAttribute("freeNum", freeNumMap.get("freeNum"));
		
		Map<String, String>  FeeRateMap = rechargeService.queryFeeRate();//提现费率
		request().setAttribute("FeeRate", FeeRateMap.get("FeeRate"));
		//可用余额
		String[] vals = moneyVal(userId);
		request().setAttribute("usableSum", vals[1]);
		
		String bankId = Convert.strToStr(request("bankId"), "-1");
		Map<String, String> bank = homeInfoSettingService.queryBankInfoById(bankId);//银行卡
		request().setAttribute("bank", bank);
		
		//预期到账日期
		Map<String, String>  expectedDate = rechargeService.queryWithdrawExpectedDate();
		request().setAttribute("expectedDate", expectedDate.get("expectedDate"));
		
		return SUCCESS;
	}
	public String withdraw_step3() throws Exception {
		//预期到账日期
		Map<String, String>  expectedDate = rechargeService.queryWithdrawExpectedDate();
		request().setAttribute("expectedDate", expectedDate.get("expectedDate"));
		return SUCCESS;
	}
	
	public String[] moneyVal(long userId) throws Exception {
		String[] val = new String[3];
		for (int i = 0; i < val.length; i++) {
			val[i] = "0";
		}
		try {
			Map<String, String> map = userService.queryUserById(userId);
			if (map != null) {
				double usableSum = Convert.strToDouble(map.get("usableSum"), 0);
				double freezeSum = Convert.strToDouble(map.get("freezeSum"), 0);
				double handleSum = usableSum + freezeSum;
				val[0] = String.format("%.2f", handleSum);// df.format(handleSum);
				val[1] = String.format("%.2f", usableSum);// df.format(usableSum);
				val[2] = String.format("%.2f", freezeSum);// df.format(freezeSum);
			}
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			throw e;
		}
		return val;
	}
	
	public String yhbound() throws Exception {
		User user = (User) session().getAttribute("user");
		Long id = user.getId();// 获得用户编号
		try {
			List<Map<String, Object>> lists = homeInfoSettingService
			.queryBankInfoList(id);
			for (Map<String, Object> map : lists) {
				if(null != map.get("cardNo")){
					String cardNo = String.valueOf(map.get("cardNo"));
					map.put("lastCardNo", cardNo.substring(cardNo.length()-6, cardNo.length()));//取银行后6位
				}
				if(null == map.get("cardUserName")){
					map.put("cardUserName", user.getRealName());//取用户真实姓名
				}
			}
			request().setAttribute("bankCardList", lists);
			request().setAttribute("realName", user.getRealName());
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
		}

		return SUCCESS;
	}
	
	public String investRecordYebDetail() throws Exception {
		User user = (User) session().getAttribute("user");
		long id = Convert.strToLong(request("id"), -1L);
		Map<String, String> map = myHomeService.queryInvestYebRecordDetail(id,user.getId());
		request().setAttribute("map", map);
		return SUCCESS;
	}
	public String matchEndowmentIndex(){
		return "success";
	}
	public String getPzInfoList()  throws Exception {
		User user = this.getUser();
		Long userId = user.getId();
		if (userId == null){
			return "login";
		}
		String curPage =SqlInfusion.FilteSqlInfusion( request().getParameter("page") == null ? "" : request().getParameter("page"));
		
		pageBean.setPageNum(curPage);
		pageBean.setPageSize(IConstants.PAGE_SIZE_5);
		try {
			userService.queryPzInfoList(userId, pageBean);
		} catch (SQLException e) {
			log.error(e);
			e.printStackTrace();
		}
		request().setAttribute("voList", pageBean.getPage());
		request().setAttribute("currentPage", pageBean.getPageNum());
		request().setAttribute("totalPageNum", pageBean.getTotalPageNum());
		return SUCCESS;
	}
	public String getWchatInfoDisclosureByBid()  throws Exception {
		String idStr = SqlInfusion.FilteSqlInfusion( request().getParameter("id") == null ? "" : request().getParameter("id"));
		int isForNewUser = Convert.strToInt(request().getParameter("isForNewUser"), 0);
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			Map<String, String> borrowDetailMap = financeService.queryBorrowDetail(id,4,isForNewUser);
			if (borrowDetailMap != null && borrowDetailMap.size() > 0) {
				request().setAttribute("productSN", "稳盈宝"+borrowDetailMap.get("borrowNumber"));
			}
			//根据借款编号查询披露信息
			List<Map<String, Object>> infodisclosureList = financeService.getInfodisclosureList(id);
			request().setAttribute("infodisclosureList", infodisclosureList);
		}
		return "success";
	}
	public String getWchatInfoDisclosureByPid()  throws Exception {
		String idStr = SqlInfusion.FilteSqlInfusion( request().getParameter("pid") == null ? "" : request().getParameter("pid"));
		String pType =SqlInfusion.FilteSqlInfusion(request().getParameter("productType") == null ? "" : request().getParameter("productType"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			Long id = Convert.strToLong(idStr, -1);
			int productType = Convert.strToInt(pType, -1);
			Map<String, String> productDetailMap = financeService.queryProductDetailById(id,productType);
			if (productDetailMap != null && productDetailMap.size() > 0) {
				if(productType == 1){
					request().setAttribute("productSN", "余额宝"+productDetailMap.get("SN"));
				}else if(productType == 2){
					request().setAttribute("productSN", "月利宝"+productDetailMap.get("SN"));
				}else if(productType == 3){
					request().setAttribute("productSN", "季发宝"+productDetailMap.get("SN"));
				}
			}
			//根据产品编号查询披露信息
			List<Map<String, Object>> infodisclosureList = financeService.getInfodisclosureListByPid(id);
			request().setAttribute("infodisclosureList", infodisclosureList);
		}
		return "success";
	}
	public String getWchatInfoDisclosureByDid()  throws Exception {
		String idStr = SqlInfusion.FilteSqlInfusion( request().getParameter("id") == null ? "" : request().getParameter("id"));
		if (!"".equals(idStr) && StringUtils.isNumericSpace(idStr)) {
			long debtId = Convert.strToLong(idStr, -1);
			Map<String, String> debtDetailMap = financeService.queryDebtDetailById(debtId);
			if (debtDetailMap != null && debtDetailMap.size() > 0) {
				long borrowId = Convert.strToLong(debtDetailMap.get("parentBId"), -1);
				int productType = Convert.strToInt(debtDetailMap.get("borrowProduct"), -1);
				if(productType == 2){
					request().setAttribute("productSN", "月利宝"+debtDetailMap.get("SN"));
				}else if(productType == 3){
					request().setAttribute("productSN", "季发宝"+debtDetailMap.get("SN"));
				}else if(productType == 4){
					request().setAttribute("productSN", "稳盈宝"+debtDetailMap.get("SN"));
				}
				//根据借款编号查询披露信息
				List<Map<String, Object>> infodisclosureList = financeService.getInfodisclosureList(borrowId);
				request().setAttribute("infodisclosureList", infodisclosureList);
			}
		}
		return "success";
	}
	
	public String weixinShare() throws Exception{
		String param = SqlInfusion.FilteSqlInfusion(request("param"));
		if (StringUtils.isNotBlank(param)) {
			DesSecurityUtil des = new DesSecurityUtil();
			Long userId = Convert.strToLong(des.decrypt(param), -1);
			String userName;
			Map<String, String> map = new HashMap<String, String>();
			try {
				map = userService.queryUserById(userId);
			} catch (Exception e) {
				log.error(e);
				e.printStackTrace();
			}
			userName = map.get("username");
			paramMap.put("refferee", userName);
		}
		paramMap.put("param", param);
		return "success";
	}
	
	public String wchatExchangeVoucher() throws Exception{
		return "success";
	}
	
	public String wchatProductInvest() throws Exception {
		// 余额宝
		Map<String, String> yebMap = financeService.queryBorrowProduct(1);
		// 月利宝
		Map<String, String> ylbMap = financeService.queryBorrowProduct(2);
		// 季发宝
		Map<String, String> jfbMap = financeService.queryBorrowProduct(3);
		// 稳赢宝
		Map<String, String> wybMap = financeService.queryWyb();
		// 债权
		Map<String, String> debtMap = financeService.queryDebt();
		
		if("1".equals(yebMap.get("productStatus"))){
			request().setAttribute("product", 1);
			request().setAttribute("id",yebMap.get("pid"));
		}else if("1".equals(ylbMap.get("productStatus"))){
			request().setAttribute("product", 2);
			request().setAttribute("id",ylbMap.get("pid"));
		}else if("1".equals(jfbMap.get("productStatus"))){
			request().setAttribute("product", 3);
			request().setAttribute("id",jfbMap.get("pid"));
		}else if("2".equals(wybMap.get("borrowStatus"))){
			request().setAttribute("product", 4);
		}else if("2".equals(debtMap.get("debtStatus"))){
			request().setAttribute("product", "debt");
		}

		return "success";
	}
}
